/*
* @Author: liyongxuan
* @Date: 2018/1/16
* @Last Modified by: liyongxuan
* @Last Modified time: 2018/1/16
* @description: 文件列表
*/
<template>
    <div>
        <div class="ca-file-main ca-box ca-p-22" v-loading.body="fullLoading">
            <div class="ca-title">
                <el-row>
                    <el-col :span="4"><h3>{{title}}</h3></el-col>
                    <el-col :span="6" class="pull-right">
                        <div class="ca-inline-block ca-m-r-10">
                            <csUploadBtn
                               :fileType="this.fileType"
                               :businessId="this.businessId"
                               :industryId="this.industryId"
                               :isShowFileChildType="false"
                               uploadType="all"
                               @getFileList="getDefaultInfo"
                               :getFileUploadedReturnData="getFileUploadedReturnDataFun"
                            ></csUploadBtn>
                        </div>
                        <el-button type="primary" size="medium" @click="save">保存</el-button>
                        <el-button type="default" size="medium" @click="cancel">取消</el-button>
                    </el-col>
                </el-row>
                <el-row>
                  <el-col :span="10">最后编辑人：{{resultData.updateUserId|getDepartmentById('userEntityList')}}</el-col>
                  <el-col :span="10">最后编辑时间：{{resultData.updateTime==''?'':$moment(resultData.updateTime).format('YYYY-MM-DD hh:mm:ss')}}</el-col>
                </el-row>
                <el-row class="ca-m-t-15">
                  <el-col :span="2">备注：
                  </el-col>
                  <el-col :span="22">
                    <el-input v-model="resultData.text" :maxlength="3000" placeholder="不超过3000字" type="textarea" :rows="3"></el-input>
                  </el-col>
                </el-row>
            </div>
            <div class="ca-file-ul">
            <el-row class="ca-file-row" :gutter="20" v-for="(file, index) in fileList.resultData" :key="index">
                <el-col :span="4" class="upload-time">{{$moment(file.uploadTime).format('YYYY-MM-DD')}}</el-col>
                <el-col :span="1">
                    <tz-icon-file-type class="ca-m-r-5" :fileType="file.fileName"></tz-icon-file-type>
                </el-col>
                <el-col :span="8">
                    <div class="ca-text-over-flow-ellipsis"
                         @click="previewFileCheck(file.id, file.fileName)">
                        <span class="ca-font-size-16 ca-pointer">{{file.fileName}}</span>
                    </div>
                </el-col>
                <el-col :span="4">
                    <div class="ca-text-over-flow-ellipsis">{{file.fileType | getNameByType }}</div>
                </el-col>
                <el-col :span="4">
                    <div class="ca-text-over-flow-ellipsis">{{file.uploadUserName}}</div>
                </el-col>
                <el-col :span="3" class="ca-pull-right ca-align-right">
                    <a class="ca-download ca-m-r-10" @click="downloadFile(file.id)"></a>
                    <el-button class="ca-table-btn" @click="deleteFile(file.id)">
                        <i class="fa fa-times"></i>
                    </el-button>
                </el-col>
            </el-row>
            <div class="ca-align-right">
                <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page="params.pageIndex"
                    :page-size="params.pageSize"
                    layout="total, prev, pager, next, jumper"
                    :total="fileList.totalCount">
                </el-pagination>
            </div>
        </div>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from '../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import mined from '__components/file-list/mixin';
    import { addRemind } from '__service/utils';
    export default {
        mixins: [mined],
        data() {
            return {
            }
        },
        watch: {},
        props: {
            title: {
                type: String,
                default() {
                    return '';
                }
            },
            // 文件类型
            fileType: {
                type: String,
                default() {
                    return '';
                }
            },
            fileChildType: {
                type: String,
                default() {
                    return '';
                }
            },
            // 业务id
            businessId: {
                type: String,
                default() {
                    return '';
                }
            },
            // 行业id
            industryId: {
                type: String,
                default() {
                    return '';
                }
            },
            //文件成功返回的数据
            getFileUploadedReturnData: { //有一个参数 fileList
                type: Function,
                default: function () {}
            },
            resultData: {
              type: Object,
              default: function () {
                return {}
              }
            }
        },
        mounted() {
            this.params = {
                ...this.params,
                fileType: this.fileType,
                fileChildType: this.fileChildType,
                businessId: this.businessId,
                industryId: this.industryId,
            };
            this.getDefaultInfo();
        },
        methods: {
            //文件成功返回的数据
            getFileUploadedReturnDataFun(arr) {
                this.getFileUploadedReturnData(arr)
            },
            // 删除文件
            deleteFile(id) {
                let params = {
                    id: id
                };
                this.$confirm('确认删除此文件?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(async () => {
                    let resData = await apiHttp(api.DELETE_FILE, params);
                    if (resData.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            type: 'success',
                            message: '删除成功!',
                            center: true
                        });
                        this.getFileList();
                    }
                })
            },
            // 切换回index
            cancel() {
                this.$emit('cancel');
                this.getDefaultInfo();
            },
            // 保存并换回index
            async save() {
                let query = {
                    itemId: this.$route.params.itemId,
                    itemTextEntities: [{
                        itemId: this.$route.params.itemId,
                        id: this.resultData.id,
                        text: this.resultData.text,
                        textType: '6'
                    }]
                }
                const { resCode } = await apiHttp(api.POST_ITEM_TEXT_ENTITY, query)
                if (resCode === STATUS_HTTP_SUCCESS) {
                    // 添加小红点
                    await addRemind({
                        dataId: this.$route.params.itemId || '', // 业务id
                        dataTab: 6, // tab页顺序 head 也为0
                        dataType: 1, // 1拟投资项目,2已投资项目,3母基金,4拟设立基金,5已设立基金,6客户,7潜在项目
                    });
                    // 根据第三方组件来调用 父组件中定义的方法 重新获取小红点
                    this.$root.Dot.$emit('getDotList');
                    this.$emit('cancel')
                }
            }
        },
        components: {
            'csUploadBtn': require('__components/upload-btn'),
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>

</style>
